<?php
namespace ZHMVC\B\TOOL;

class FileToApi
{
    private $_table;
    private $_file1;
    private $_path1;
    private $_pre;
    private $_content1;//数据管理类

    
    public function __construct($pre,$tablename,$pathname1,$filename1,$modulename)
    {
        $this->_table=$pre.$tablename;
        $this->_file1=$filename1;
        $this->_path1=$pathname1;
       
        $this->content1='<?php
namespace '.strtoupper($modulename).'\\D;
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Pragma: no-cache"); 
// 制定允许其他域名访问
header("Access-Control-Allow-Origin:*");
// 响应类型
header("Access-Control-Allow-Methods:POST");
// 响应头设置
header("Access-Control-Allow-Headers:x-requested-with, content-type");
ini_set("date.timezone","Asia/Shanghai");
define("SIGNATURE","BRAVEGUO");
define("ISZHMVCAPIBUG",FALSE);
include(dirname(dirname(dirname(__FILE__)))."/zhconfig/Config.php");
session_start();
if(ISZHMVCAPIBUG==true)
{
    error_reporting(E_ALL);
    ini_set("display_errors", "1");
}
else
{
    error_reporting(0);//E_ALL 0
    ini_set("display_errors", "0");//1 0
}
$token = SafeRequest(getPGC("token"), 0);
$timestamp = SafeRequest(getPGC("timestamp"), 0);
$randomstr = SafeRequest(getPGC("randomstr"), 0);

$returnS = array(
    "code" => "0",
    "data" => array(),
    "msg" => "ok",
    "message" => "成功请求",
    "updateDime" => intval(time())
);

$rs1=new \ZHMVC\D\Module();
$datas=$rs1->getAll();
$rows = $rs1->getRowCount();
for ($i = 0; $i < $rows; $i++) {
    $datas[$i]["button"]["id"]=$datas[$i]["id"];
}

$returnS["data"]=$datas;
$result = json_encode($returnS);
echo $result;
exit();
';
    }
    
    public function saveContent()
    {
        
        $filepath1=ZH_PATH.DS.$this->_path1.$this->_file1. ZH;
        
        if (file_exists($filepath1)) {
        
        } else {
            $fp = fopen($filepath1,'w');
            fwrite($fp,$this->content1);
            fclose($fp);
        }
       
    }
    
}